<#include "/admin/inc/page.html">
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文章 - UnaBoot</title>
    <link rel="icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <link rel="stylesheet" href="${una}/ub-admin/plugin/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/font-awesome.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/ionicons.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/adminlte.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/unaboot-admin.css">
    <link rel="stylesheet" href="${una}/ub-admin/plugin/layer/skin/default/layer.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700">
</head>
<body class="sidebar-mini layout-fixed layout-navbar-fixed text-md <!--sidebar-collapse-->">
    <div class="wrapper">
        <nav class="main-header navbar navbar-expand navbar-white navbar-light">
            <#include "/admin/inc/header.html">
        </nav>
        <aside class="main-sidebar sidebar-dark-primary ">
            <#include "/admin/inc/aside.html">
        </aside>
        <div class="content-wrapper bg-gray-custom">
            <div class="content-header pb-0">
                <div class="row mb-2">
                    <div class="col-12">
                        <h4 class="ml-2 mb-0 text-dark">文章 <a href="${una}/admin/posts/create" class="btn btn-sm btn-outline-primary">写文章</a></h4>
                    </div>
                </div>
            </div>
            <div class="content">
                <div class="container-fluid">
                    <!--条件查找-->
                    <div class="row text-sm">
                        <div class="col-12">
                            <div class="pull-left post-select">
                                <a href="${una}/admin/posts/" class="post-current">全部<span class="count">（${total}）</span></a> |
                                <a href="${una}/admin/posts/actives" >已发布<span class="count">（${published}）</span></a>
                            </div>
                        </div>
                    </div>
                    <!--过滤选项栏-->
                    <@shiro.hasRole name="admin">
                        <div class="row text-sm mt-1">
                            <div class="col-12">
                                <form action="${una}/admin/posts/" method="get" class="form-inline form-row">
                                    <input name="key" id="key" placeholder="关键词" class="form-control form-control-sm mb-2 mr-sm-2">
                                    <select class="form-control form-control-sm mb-2 mr-sm-2" id="userId" name="userId">
                                        <option value="-10" style="display: none">所有用户</option>
                                        <#if users?? && users?size gt 0>
                                            <#list users as user>
                                                <option value="${user.id}">${user.nickname!user.username}</option>
                                            </#list>
                                        </#if>
                                    </select>
                                    <select class="form-control form-control-sm mb-2 mr-sm-2" id="category" name="category">
                                        <option value="-10"  style="display: none;">所有分类栏目</option>
                                        <#if categories?? && categories?size gt 0>
                                            <#list categories as category>
                                                <option value="${category.id}">${category.name}</option>
                                            </#list>
                                        </#if>
                                    </select>
                                    <select class="form-control form-control-sm mb-2 mr-sm-2" id="status" name="status">
                                        <option value="-10"  style="display: none;">所有状态</option>
                                        <option value="-1">草稿</option>
                                        <option value="0">审核中</option>
                                        <option value="2">发布中</option>
                                        <option value="1">已发布</option>
                                    </select>
                                    <select class="form-control form-control-sm mb-2 mr-sm-2" id="style" name="style">
                                        <option value="-1"  style="display: none;">所有类型</option>
                                        <option value="0">文章</option>
                                        <option value="1">文档</option>
                                    </select>
                                    <button type="submit" class="btn btn-sm btn-primary ml-2 mb-2"> 筛选</button>
                                </form>
                            </div>
                        </div>
                    </@shiro.hasRole>
                    <!--数据列表-->
                    <div class="row text-sm mt-1">
                        <div class="col-12">
                            <table class="table post-datatable table-striped table-hover" style="border: 1px solid #ddd">
                                <thead>
                                    <tr class="bg-white">
                                        <td width="30%">标题</td><td width="10%">封面</td><td>作者</td><td>分类</td><td>标签</td><td>日期</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    <#if data.content?? && data.content?size gt 0>
                                        <#list data.content as post>
                                            <tr>
                                                <td>
                                                    <#if post.status == -1>
                                                        <span class="text-secondary">[草稿]</span>
                                                    <#elseif post.status == 0>
                                                        <span class="text-danger">[审核中]</span>
                                                    <#elseif post.status == 2>
                                                        <span class="text-yellow">[定时发布]</span>
                                                    <#else>
                                                        <span class="text-green">[已发布]</span>
                                                    </#if>
                                                    <#if post.source == 0>
                                                        <span class="tag tag-blue">原创</span>
                                                    </#if>
                                                    <#if post.status == 1>
                                                        <#if post.stick == true>
                                                            <span class="tag tag-red">置顶</span>
                                                        </#if>
                                                        <#if post.recommend == true>
                                                            <span class="tag tag-blue">推荐</span>
                                                        </#if>
                                                    </#if>
                                                    <a href="javascript:void(0);">
                                                        ${post.title}
                                                    </a>
                                                    <div class="row-actions">
                                                        <span class="undo">
                                                            <a href="javascript:void(0);" aria-id="${post.id}"><i class="fa fa-undo"></i>撤销</a>
                                                        </span>
                                                    </div>
                                                </td>
                                                <td>
                                                    <#if post.thumb?? && post.thumb != "">
                                                        <img src="${post.thumb}" class="img-fluid post-thumb">
                                                    <#else>
                                                        <img src="${una}/ub-admin/img/thumb.jpg" class="img-fluid post-thumb">
                                                    </#if>

                                                </td>
                                                <td>
                                                    <a href="javascript:void(0)">
                                                        <#if post.userId == profile.id>
                                                            我自己
                                                        <#else>
                                                            ${post.author}
                                                        </#if>
                                                    </a>
                                                </td>
                                                <td>
                                                    <#if post.category??>
                                                        <span class="tag tag-red">${post.category.name}</span>
                                                    <#else>
                                                        <span class="tag tag-red">Uncategoried</span>
                                                    </#if>
                                                </td>
                                                <td>
                                                    <#if post.tags?? && post.tags?size gt 0>
                                                        <#list post.tags as tag>
                                                            <span class="tag tag-blue">${tag.name}</span>
                                                        </#list>
                                                    </#if>
                                                </td>
                                                <td>
                                                    <#if post.status == -1>
                                                        创建于<br>
                                                    <#elseif post.status == 0>
                                                        审核中<br>
                                                    <#else>
                                                        已发布<br>
                                                    </#if>
                                                    <span class="post-time"><i class="fa fa-calendar-o"></i> ${post.createTime?string("yyyy-MM-dd HH:ss")}</span>
                                                </td>
                                            </tr>
                                        </#list>
                                    <#else>
                                        <tr><td colspan="6" class="text-center">暂无任何文章</td></tr>
                                    </#if>
                                </tbody>
                                <tfoot>
                                    <tr class="bg-white">
                                        <td width="30%">标题</td><td width="10%">封面</td><td>作者</td><td>分类</td><td>标签</td><td>日期</td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                    <!--分页按钮-->
                    <div class="row text-sm mt-1">
                        <#if data?? && data.content?size gt 0 && data.totalPages gt 1>
                            <div class="col-12">
                                <nav aria-label="..." class="pull-right">
                                    <@pagination una+"/admin/actives/"+(urlParam!'') data 9/>
                                </nav>
                            </div>
                        </#if>
                    </div>
                </div>
            </div>
        </div>
        <footer class="main-footer">
            <#include "/admin/inc/footer.html">
        </footer>
    </div>
    <script src="${una}/ub-admin/plugin/jquery/jquery.min.js" type="text/javascript"></script>
    <script src="${una}/ub-admin/plugin/bootstrap/js/bootstrap.bundle.min.js" type="text/javascript"></script>
    <script src="${una}/ub-admin/js/adminlte.js" type="text/javascript"></script>
    <script src="${una}/ub-admin/plugin/layer/layer.js" type="text/javascript"></script>
    <script src="${una}/ub-admin/js/unaboot-admin.core.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(".undo a").on("click",function(){
            var id = $(this).attr("aria-id");
            if(id == null || typeof(id) == 'undefined' ){
                return false;
            }else{
                layer.alert("你是否确定撤回本次发布请求？",{
                    title:"<i class='fa fa-info-circle'></i> 提示",
                    icon:0,
                    btn:['是(Y)','否(N)'],
                    offset:['55px'],
                    shadeClose: false,
                    shade:[0.4,'#fff'],
                    anim: 1
                },function(){
                    var load = layer.load(2,{shade:[0.4,'#f0f0f0']});
                    $.ajax({
                        type:'PUT',
                        url:"${una}/admin/posts/undo/"+id,
                        success:function(){
                            layer.close(load);
                            layer.alert("撤销后将取消发布状态，你可以在草稿箱中找到该文章",{
                                title:"<i class='fa fa-info'></i> 提示",
                                icon:1,
                                shade:[0.4,"#fff"],
                                shadeClose:false,
                                time:0,
                                btn:['OK'],
                                yes:function(index){
                                    layer.close(index);
                                    window.location.href="${una}/admin/posts/?offset=${data.number+1}";
                                }
                            });
                        },
                        error:function(){
                            layer.close(load);
                            layer.alert("当前操作失败!请稍后再试。",{
                                title:"<i class='fa fa-info'></i> 提示",
                                icon:1,
                                shade:[0.4,"#fff"],
                                shadeClose:false,
                                time:0,
                                btn:['Close'],
                                yes:function(newIndex){
                                    layer.close(newIndex);
                                }
                            });
                        }
                    });
                },function(index){
                    layer.close(index);
                });
            }
        });
    </script>
</body>
</html>